#include <stdlib.h>
 
int a = 10;
void func (void){
    char *buff = (char*)malloc(30);
}
 
int main (void){
    func(); // 产生内存泄漏
    return 0;
}

/* 内存泄露排查方式：
    通过gcc -g leak.c -o leak命令进行编译
    执行valgrind --leak-check=full ./leak

*/
/* valgrind 内存泄露定位如下：
    mkdir -p /home/hubery/hubery/gitee/hpc_hu/output
    gcc -g /home/hubery/hubery/gitee/hpc_hu/demo/algo_code/day9.c -o /home/hubery/hubery/gitee/hpc_hu/output/day9
    valgrind --leak-check=full /home/hubery/hubery/gitee/hpc_hu/output/day9
    ==32760== Memcheck, a memory error detector
    ==32760== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==32760== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
    ==32760== Command: /home/hubery/hubery/gitee/hpc_hu/output/day9
    ==32760== 
    ==32760== 
    ==32760== HEAP SUMMARY:
    ==32760==     in use at exit: 30 bytes in 1 blocks
    ==32760==   total heap usage: 1 allocs, 0 frees, 30 bytes allocated
    ==32760== 
    ==32760== 30 bytes in 1 blocks are definitely lost in loss record 1 of 1
    ==32760==    at 0x4C31B0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==32760==    by 0x10865B: func (day9.c:5)
    ==32760==    by 0x10866B: main (day9.c:9)
    ==32760== 
    ==32760== LEAK SUMMARY:
    ==32760==    definitely lost: 30 bytes in 1 blocks
    ==32760==    indirectly lost: 0 bytes in 0 blocks
    ==32760==      possibly lost: 0 bytes in 0 blocks
    ==32760==    still reachable: 0 bytes in 0 blocks
    ==32760==         suppressed: 0 bytes in 0 blocks
    ==32760== 
    ==32760== For counts of detected and suppressed errors, rerun with: -v
    ==32760== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

*/